from aiogram_dialog import DialogManager

from poker_bot.core.models.enums.user import UserRole
from poker_bot.database.services import AccountService, UserService


async def user_info_getter(
    dialog_manager: DialogManager,
    user_service: UserService,
    account_service: AccountService,
    **kwargs
):
    user_id: int = dialog_manager.event.from_user.id
    user = await user_service.get_user_by_telegram_id(user_id)

    account = await account_service.get_account_by_id(user.selected_account_id)

    return {
        "account_id": account.account_id,
        "is_subscribed": user.is_subscribed,
    }


async def user_role_getter(
    dialog_manager: DialogManager, user_service: UserService, **kwargs
):
    user_id: int = dialog_manager.event.from_user.id

    user = await user_service.get_user_by_telegram_id(user_id)

    return {
        "user_is_admin": user.role == UserRole.admin,
    }


async def user_accounts_getter(
    dialog_manager: DialogManager, account_service: AccountService, **kwargs
):
    user_id: int = dialog_manager.event.from_user.id

    accounts = await account_service.get_user_accounts(user_id)

    return {
        "accounts": accounts,
    }
